package com.rcd2.web.servlet.old; /**
 * ClassName:${NAME}
 * Package:${PACKAGE_NAME}
 * ProjectName:servlet
 * Description:
 *
 * @Date:2022/2/9 16:35
 * @Author:Mrhan
 */

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.rcd2.pojo.Brand;
import com.rcd2.service.BrandService;
import com.rcd2.service.impl.BrandServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet("/selectAllServlet")
public class SelectAllServlet extends HttpServlet {

    /*通过BrandService实现类BrandServiceImpl, 生成BrandService接口对象(含有实现类中所有的内容)*/
    private BrandService brandService = new BrandServiceImpl();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        List<Brand> brands = brandService.selectAll();
        String jsonString = JSON.toJSONString(brands);
        response.setContentType("text/json;charset=utf-8");
        response.getWriter().write(jsonString);

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
